package cn.com.infcn.util.mss;

import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.alibaba.fastjson.JSON;
/**
 * 创建索引api
 *
 * @author Ansj
 */

@Repository
public class MssInitApi {

	@Autowired
	private TransportClient mssEsClient;
	private String source="{\n" +
			"  \"settings\": {\n" +
			"    \"index\": {\n" +
			"      \"number_of_shards\": \"10\",\n" +
			"      \"number_of_replicas\": \"1\"\n" +
			"    }\n" +
			"  },\n" +
			"  \"mappings\": {\n" +
			"    \"edu\": {\n" +
			"      \"dynamic_templates\": [\n" +
			"        {\n" +
			"          \"default_template\": {\n" +
			"            \"mapping\": {\n" +
			"              \"include_in_all\": false,\n" +
			"              \"ignore_above\": 255,\n" +
			"              \"type\": \"string\"\n" +
			"            },\n" +
			"            \"match_mapping_type\": \"string\",\n" +
			"            \"match\": \"*\"\n" +
			"          }\n" +
			"        }\n" +
			"      ],\n" +
			"      \"_all\": {\n" +
			"        \"analyzer\": \"standard\"\n" +
			"      },\n" +
			"      \"date_detection\": false,\n" +
			"      \"properties\": {\n" +
			"        \"owner\": {\n" +
			"          \"include_in_all\": false,\n" +
			"          \"analyzer\": \"keyword\",\n" +
			"          \"ignore_above\": 255,\n" +
			"          \"type\": \"string\"\n" +
			"        },\n" +
			"        \"user_ids\": {\n" +
			"          \"include_in_all\": false,\n" +
			"          \"analyzer\": \"keyword\",\n" +
			"          \"ignore_above\": 255,\n" +
			"          \"type\": \"string\"\n" +
			"        },\n" +
			"        \"upload_year\": {\n" +
			"          \"include_in_all\": false,\n" +
			"          \"analyzer\": \"keyword\",\n" +
			"          \"ignore_above\": 255,\n" +
			"          \"type\": \"string\"\n" +
			"        },\n" +
			"        \"pub_folder_id\": {\n" +
			"          \"include_in_all\": false,\n" +
			"          \"analyzer\": \"keyword\",\n" +
			"          \"ignore_above\": 255,\n" +
			"          \"type\": \"string\"\n" +
			"        },\n" +
			"        \"title\": {\n" +
			"          \"include_in_all\": false,\n" +
			"          \"analyzer\": \"index_ansj\",\n" +
			"          \"type\": \"string\"\n" +
			"        },\n" +
			"        \"content\": {\n" +
			"          \"include_in_all\": false,\n" +
			"          \"analyzer\": \"index_ansj\",\n" +
			"          \"type\": \"string\"\n" +
			"        },\n" +
			"        \"enabled\": {\n" +
			"          \"include_in_all\": false,\n" +
			"          \"analyzer\": \"keyword\",\n" +
			"          \"ignore_above\": 255,\n" +
			"          \"type\": \"string\"\n" +
			"        },\n" +
			"        \"tags\": {\n" +
			"          \"include_in_all\": false,\n" +
			"          \"analyzer\": \"keyword\",\n" +
			"          \"ignore_above\": 255,\n" +
			"          \"type\": \"string\"\n" +
			"        },\n" +
			"        \"_insert_time\": {\n" +
			"          \"include_in_all\": false,\n" +
			"          \"format\": \"strict_date_optional_time||epoch_millis\",\n" +
			"          \"type\": \"date\"\n" +
			"        },\n" +
			"        \"my_folder_id\": {\n" +
			"          \"include_in_all\": false,\n" +
			"          \"ignore_above\": 255,\n" +
			"          \"type\": \"string\"\n" +
			"        },\n" +
			"        \"size\": {\n" +
			"          \"include_in_all\": false,\n" +
			"          \"analyzer\": \"keyword\",\n" +
			"          \"ignore_above\": 255,\n" +
			"          \"type\": \"string\"\n" +
			"        },\n" +
			"        \"_ids\": {\n" +
			"          \"include_in_all\": false,\n" +
			"          \"ignore_above\": 255,\n" +
			"          \"index\": \"no\",\n" +
			"          \"type\": \"string\"\n" +
			"        },\n" +
			"        \"manager_id\": {\n" +
			"          \"include_in_all\": false,\n" +
			"          \"ignore_above\": 255,\n" +
			"          \"type\": \"string\"\n" +
			"        },\n" +
			"        \"user_id\": {\n" +
			"          \"include_in_all\": false,\n" +
			"          \"analyzer\": \"keyword\",\n" +
			"          \"ignore_above\": 255,\n" +
			"          \"type\": \"string\"\n" +
			"        },\n" +
			"        \"file_type\": {\n" +
			"          \"include_in_all\": false,\n" +
			"          \"analyzer\": \"keyword\",\n" +
			"          \"ignore_above\": 255,\n" +
			"          \"type\": \"string\"\n" +
			"        },\n" +
			"        \"pub_folder\": {\n" +
			"          \"include_in_all\": false,\n" +
			"          \"analyzer\": \"keyword\",\n" +
			"          \"ignore_above\": 255,\n" +
			"          \"type\": \"string\"\n" +
			"        },\n" +
			"        \"id\": {\n" +
			"          \"include_in_all\": false,\n" +
			"          \"analyzer\": \"keyword\",\n" +
			"          \"ignore_above\": 255,\n" +
			"          \"type\": \"string\"\n" +
			"        },\n" +
			"        \"upload_datetime\": {\n" +
			"          \"include_in_all\": false,\n" +
			"          \"format\": \"strict_date_optional_time||epoch_millis\",\n" +
			"          \"type\": \"date\"\n" +
			"        },\n" +
			"        \"my_folder\": {\n" +
			"          \"include_in_all\": false,\n" +
			"          \"ignore_above\": 255,\n" +
			"          \"type\": \"string\"\n" +
			"        },\n" +
			"        \"upload_date\": {\n" +
			"          \"include_in_all\": false,\n" +
			"          \"format\": \"strict_date_optional_time||epoch_millis\",\n" +
			"          \"type\": \"date\"\n" +
			"        }\n" +
			"      }\n" +
			"    },\n" +
			"    \"_default_\": {\n" +
			"      \"dynamic_templates\": [\n" +
			"        {\n" +
			"          \"default_template\": {\n" +
			"            \"mapping\": {\n" +
			"              \"include_in_all\": false,\n" +
			"              \"ignore_above\": 255,\n" +
			"              \"type\": \"string\"\n" +
			"            },\n" +
			"            \"match_mapping_type\": \"string\",\n" +
			"            \"match\": \"*\"\n" +
			"          }\n" +
			"        }\n" +
			"      ],\n" +
			"      \"date_detection\": false\n" +
			"    }\n" +
			"  }\n" +
			"}";
	
	public void initMapping() {
		String mapping = source;
		CreateIndexResponse createIndexResponse = mssEsClient.admin().indices().prepareCreate("edu_aa").setSource(mapping).get();
		System.out.println(JSON.toJSONString(createIndexResponse,true));
	}


}
